package com.bw.day11.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bw.day11.dao.ClaimDao;
import com.bw.day11.entity.Claim;
import com.bw.day11.entity.Detail;
import com.bw.day11.service.ClaimService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Service
public class ClaimServiceImpl implements ClaimService{
	@Autowired
	private ClaimDao claimDao;
	//条件查询
	public PageInfo<Claim> getlist(Integer pageNum, Integer pageSize, Claim claim) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageNum, pageSize);
		List<Claim> claims = claimDao.getlist(claim);
		
		return new PageInfo<Claim>(claims);
	}
	@Override
	public Claim selectid(String id) {
		// TODO Auto-generated method stub
		
		Claim info = claimDao.selectid(id);
		return info;
	}
	@Override
	public void insertclaim(Claim claim) {
		// TODO Auto-generated method stub
		List<Detail> collect = claim.getDetails().stream().filter(cla->cla.getType()!=null).collect(Collectors.toList());
		claim.setDetails(collect);
		for (Detail detail : collect) {
			System.out.println(detail);
		}
		if (claim.getId()!=null && claim.getId()!="") {
			claimDao.deletedetail(claim.getId());
			claimDao.deleteclaim(claim.getId());
			claimDao.insertclaim(claim);
			claimDao.insertdetail(claim);
		}
	}

}
